﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Music_Organizer
{
    public partial class RootFoldersForm : Form
    {
        private bool oK_Click;
        private string origCloudRoot = null;
        private string origMusicRoot = null;

        /// <summary>
        /// Initialize class.
        /// </summary>
        public RootFoldersForm()
        {
            InitializeComponent();

            oK_Click = false;
        }

        /// <summary>
        /// Initialize class.
        /// </summary>
        /// <param name="CloudRoot">
        /// Path for the cloud root directory.
        /// </param>
        /// <param name="LocalMusicRoot">
        /// Path for the local music root directory.
        /// </param>
        public RootFoldersForm(string CloudRoot, string LocalMusicRoot)
        {
            InitializeComponent();

            oK_Click = false;

            tbCloudRoot.Text = CloudRoot;
            tbLocalMusic.Text = LocalMusicRoot;
        }

        /// <summary>
        /// Event occurs when the cloud root directory browse button is clicked
        /// </summary>
        private void bCloudBrowse_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog tmpDialog = new System.Windows.Forms.FolderBrowserDialog();
            tmpDialog.SelectedPath = tbCloudRoot.Text;
            tmpDialog.ShowDialog();
            tbCloudRoot.Text = tmpDialog.SelectedPath;
        }

        /// <summary>
        /// Event occurs when the local music director browse button is clicked
        /// </summary>
        private void bLocalMusicBrowse_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog tmpDialog = new System.Windows.Forms.FolderBrowserDialog();
            tmpDialog.SelectedPath = tbLocalMusic.Text;
            tmpDialog.ShowDialog();
            tbLocalMusic.Text = tmpDialog.SelectedPath;
        }

        /// <summary>
        /// Event occurs when the ok button is clicked
        /// </summary>
        private void bOK_Click(object sender, EventArgs e)
        {
            oK_Click = true;
            this.Close();
        }

        /// <summary>
        /// Event occurs when cancel button is clicked
        /// </summary>
        private void bCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Get or set the cloud root directory.
        /// </summary>
        public string CloudRoot
        {
            get { return tbCloudRoot.Text; }
            set { tbCloudRoot.Text = value; }
        }

        /// <summary>
        /// Get or set the local music directory.
        /// </summary>
        public string LocalMusic
        {
            get { return tbLocalMusic.Text; }
            set { tbLocalMusic.Text = value; }
        }

        /// <summary>
        /// Returns true if the ok button was clicked.
        /// </summary>
        public bool OK_Click
        {
            get { return oK_Click; }
        }

        /// <summary>
        /// Event that occus when the form is first displayed.
        /// </summary>
        private void RootFoldersForm_Shown(object sender, System.EventArgs e)
        {
            if (tbCloudRoot.Text != "")
                origCloudRoot = tbCloudRoot.Text;
            else
                throw new Exception("Cloud Root is Empty");
            
            if (tbLocalMusic.Text != "")
                origMusicRoot = tbLocalMusic.Text;
            else
                throw new Exception("Local Music Root is Empty");
        }


        /// <summary>
        /// Event that occus when the form is closing.
        /// </summary>
        void RootFoldersForm_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            if (!oK_Click)
            {
                if (origCloudRoot != null)
                {
                    tbCloudRoot.Text = origCloudRoot;
                }
                if (origMusicRoot != null)
                {
                    tbLocalMusic.Text = origMusicRoot;
                }
            }
        }







    }
}
